<template>
	<view class="home">
		<swiper indicator-dots circular>
			<swiper-item v-for="item in swipers" :key="item.id">
				<image :src="item.img"></image>
			</swiper-item>
			
		<!-- 	<swiper-item>
				<image src="http://destiny001.gitee.io/image/ban1.jpg"></image>
			</swiper-item>
			<swiper-item>
				<image src="http://destiny001.gitee.io/image/ban2.jpg"></image>
			</swiper-item>
			<swiper-item>
				<image src="http://destiny001.gitee.io/image/ban3.jpg"></image>
			</swiper-item>
			<swiper-item>
				<image src="http://destiny001.gitee.io/image/ban4.jpg"></image>
			</swiper-item> -->
		</swiper>
		
		<!-- 导航区域 -->
		<view class="nav">
			<view class="nav_item" v-for="(item,index) in navs" :key="index" @click="navItemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
		</view>
		<!-- 推荐商品区域 -->
		<view class="hot_goods">
			<view class="tit">推荐商品</view>
			<goods-list @goodsItemClick="goGoodsDetail" :goods="goods"></goods-list>
		</view>
	</view>
</template>
<script>
	import goodsList from "../../components/goods-list/goods-list.vue"
	export default {
		data() {
			return {
				swipers:[],
				goods:[],
				navs:[
					{
					icon:"iconfont icon-ziyuan",
					title:"因月明超市",
					path:"/pages/goods/goods",
				},
				{
					icon:"iconfont icon-guanyuwomen",
					title:"联系我们",
					path:"/pages/contcat/contcat",
				},
				{
					icon:"iconfont icon-tupian",
					title:"社区图片",
					path:"/pages/pics/pics",
				},
				{
					icon:"iconfont icon-shipin",
					title:"学习视频",
					path:"/pages/videos/videos",
				},
				]
				
			}
		},
		onLoad() {
			this.getSwipers()
			this.getHotGoods()
		},
		components:{
			"goods-list":goodsList
		},
		methods: {
			// 获取轮播图数据
			async getSwipers (){
				const res = await this.$myRequest({
					url:'api/getlunbo/'
				})
				// console.log(res)
				this.swipers = res.data.message
				},
				
				 
			// getSwipers (){
				// console.log("获取轮播图的数据")
				// uni.request({
				// 	url:"https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata",
				// 	success: res=>{
				// 		console.log(res)
				// 		if(res.data.meta.status !== 200){
				// 			return uni.showToast({
				// 				title:"获取数据失败"
				// 			})
				// 		}
				// 		this.swipers = res.data.message
				// 	}
				// })
			// }
			
			// async getSwipers () {
			// 	const res = await uni.request({
			// 		url:"http://localhost:8082/api/getlunbo"
			// 	})
			// 	console.log(res)
			// },
			
			// 获取热门商品列表数据
			async getHotGoods(){
				const res = await this.$myRequest({
					url:'api/getgoods?pageindex=1'
				})
				this.goods = res.data.message
				// 接口报错 会阻塞后续的代码正常运行
				//在家开发  模拟后端接口调用 获得了GOODS的数据
				// this.goods = [{
				// 	title: 666
				// }, {
				// 	title: 555	
				// }]
			},
			// 导航点击的处理函数
			navItemClick(url){
				// console.log(url)
				// console.log("跳转呗")
				uni.navigateTo({
					url
				})
			},
			goGoodsDetail(){
				uni.navigateTo({
					url:'/pages/goods-detail/goods-detail'
				})
			}
		}
	}	
</script>

<style lang="scss">
	.home{
		swiper{
			width: 750rpx;
			height: 380rpx;
			image{
				height: 100%;
				width: 100%;
			}
		}
		.nav{
			display: flex;
			.nav_item{
				width: 25%;
				text-align:center;
				view{
					width: 120rpx;
					height: 120rpx;
					background: $shop-color;
					border-radius: 50%;
					margin: 10px auto;
					line-height: 120rpx;
					color: #fff;
					font-size: 50rpx;
				}
				.icon-tupian{
					font-size: 45rpx;
				}
				text{
					font-size: 30rpx;
					
				}
			}
		}
		.hot_goods{
			background:#eee ;
			overflow: hidden;
			margin-top: 10rpx;
			.tit{
				height: 100rpx;
				line-height: 100rpx;
				color: $shop-color ;
				text-align: center;
				letter-spacing: 40rpx;
				background: #fff;
				margin: 7rpx 0;
			}
			
		}
	}
</style>
